package indi.zhifa.recipe.bailan.busy.devicemgr.gen;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.fill.Column;
import com.baomidou.mybatisplus.generator.fill.Property;
import indi.zhifa.recipe.bailan.framework.mysql.entity.po.BaseEntity;
import indi.zhifa.recipe.bailan.framework.mysql.service.IZfDbService;
import indi.zhifa.recipe.bailan.framework.mysql.service.impl.ZfDbServiceImpl;

public class MapperGenerator {

    public static void main(String args[]){
        originGen();
    }

    static void originGen(){
        String outputPath =  "E:\\DOCUMENT\\generator\\bailan4";

        FastAutoGenerator.create("jdbc:mysql://localhost:3306/auth-test?useUnicode=true&characterEncoding=utf-8",
                        "dbMgr", "qqhilvMgAl@7")
                .globalConfig(builder -> {
                    // 设置作者
                    builder.author("织法")
                            // 开启 swagger 模式
                            .enableSwagger()
                            // 覆盖已生成文件
                            .fileOverride()
                            // 指定输出目录
                            .outputDir(outputPath);
                })
                .packageConfig(builder -> {
                    // 设置父包名
                    builder.parent("indi.zhifa.recipe.bailan.busy")
                            // 指定模块名称
                            .moduleName("devicemgr")
                            .entity("entity.po")
                            .service("dao.service")
                            .serviceImpl("dao.service.impl")
                            .mapper("dao.mapper");

                })
                .strategyConfig(builder -> {
                    // 设置过滤表前缀
                    builder.addTablePrefix("busy_","sys_")
                            .addExclude("sys_user","sys_role","sys_rel_user_role","sys_department")
                            .entityBuilder()
                            .enableLombok()
                            .enableRemoveIsPrefix()
                            .logicDeleteColumnName("del")
                            .logicDeletePropertyName("del")
                            .addTableFills(new Column("create_time", FieldFill.INSERT))
                            .addTableFills(new Property("createTime", FieldFill.INSERT))
                            .addTableFills(new Column("create_by",FieldFill.INSERT))
                            .addTableFills(new Property("createBy",FieldFill.INSERT))
                            .addTableFills(new Column("create_name",FieldFill.INSERT))
                            .addTableFills(new Property("createName",FieldFill.INSERT))
                            .addTableFills(new Column("create_ip",FieldFill.INSERT))
                            .addTableFills(new Property("createIp",FieldFill.INSERT))

                            .addTableFills(new Column("modify_time", FieldFill.UPDATE))
                            .addTableFills(new Property("modifyTime", FieldFill.UPDATE))
                            .addTableFills(new Column("modify_by",FieldFill.UPDATE))
                            .addTableFills(new Property("modifyBy",FieldFill.UPDATE))
                            .addTableFills(new Column("modify_name",FieldFill.UPDATE))
                            .addTableFills(new Property("modifyName",FieldFill.UPDATE))
                            .addTableFills(new Column("modify_ip",FieldFill.UPDATE))
                            .addTableFills(new Property("modifyIp",FieldFill.UPDATE))

                            .idType(IdType.ASSIGN_ID)
                            .formatFileName("%sEntity")
                            .entityBuilder()
                            .superClass(BaseEntity.class)
                            .disableSerialVersionUID()
                            .enableLombok()
                            .versionColumnName("version")
                            .versionPropertyName("version")
                            .addSuperEntityColumns("id","create_time","create_by","create_name","create_ip","modify_by","modify_time","modify_name","modify_ip","version","del")
                            .serviceBuilder()
                            .formatServiceFileName("I%sDbService")
                            .formatServiceImplFileName("%sDbServiceImpl")
                            .superServiceClass(IZfDbService.class)
                            .superServiceImplClass(ZfDbServiceImpl.class);
                })
                // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .templateEngine(new FreemarkerTemplateEngine())
                .templateConfig(templet->{
                    templet.entity("templates/MyEntity.java");
                    templet.mapper("templates/MyMapper.java");
                    //templet.mapperXml("templates/MyMapper.xml");
                    templet.service("templates/MyService.java");
                    templet.serviceImpl("templates/MyServiceImpl.java");
                    templet.controller("templates/MyController.java");
                })
                .execute();
    }

}
